<?php
namespace common\models;

use Yii;
use yii\db\ActiveRecord;
use common\models\Article;

class Superstar extends ActiveRecord{

    public static function tableName()
    {
        return 'superstar';
    }
    //获取对应文章总数
    public function getCount()
    {
        return $this->hasOne(Article::className(), ['ss_id' => 'ss_id'])->count();
    }
    public function getFirstSuiperByAccount($ss_id)
    {
        $positive = Article::find()
            ->where(['and',['=','ss_id',$ss_id],['>','atcl_negative_prob','0.75']])
            ->count();
        $ret['positive'] = $positive;
        $negative = Article::find()
            ->where(['and',['=','ss_id',$ss_id],['<','atcl_negative_prob','0.25']])
            ->count();
        $ret['negative'] = $negative;
        $neutral = Article::find()
            ->where(['and',['=','ss_id',$ss_id],['between','atcl_negative_prob','0.25','0.75']])
            ->count();
        $ret['neutral'] = $neutral;
        return $ret;
    }
    public function fields() {
        return [
            'id'=>'ss_id',
            'name'=>'ss_name',
            'keywords'=>'ss_keywords',
            'count'=>function($model)
            {
                return $model->count;
            }
        ];
    }

}